#!/bin/bash
PROJECT_DIR=/root/projects/study_share/web_demo
LOG_DIR=/root/logs
echo "进入目录$PROJECT_DIR"
cd $PROJECT_DIR
echo "开始拉取代码"
git checkout $1
git pull
echo "停止正在运行的项目"
pid=$(jps -l | grep $PROJECT_DIR/admin/target/admin.jar | awk '{print $1}')
if [ -n "$pid" ];then
  kill -15 $pid
  for i in {1..15}
  do
    pid=$(jps -l | grep $PROJECT_DIR/admin/target/admin.jar | awk '{print $1}')
    if [ -z $pid ]; then
      echo "renren-security的admin服务已结束"
      break
    else
      echo "正在结束中，请等待..."
      sleep 1
    fi
  done
  kill -9 $pid
fi
echo "正在编译java代码"
mvn clean package -Dmaven.test.skip=true
echo "开始运行jar包"
nohup java -jar $PROJECT_DIR/admin/target/admin.jar --spring.profiles.active=prod > $LOG_DIR/renren.log 2>&1 &
echo "运行完毕，日志文件为$LOG_DIR/renren.log"
